[XENTRACE] Remember number of lost trace records when
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Mon, 10 Jul 2006 16:05:44 +0000 (17:05 +0100)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Mon, 10 Jul 2006 16:05:44 +0000 (17:05 +0100)
trace buffer is full and write a 'number of lost records'
entry when space becomes available.
From: Rob Gardner <rob.gardner@hp.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
xen/common/trace.c
xen/include/public/trace.h

index 7e480d0bb402e9acfb9ca5f16ed5ac3f3d199412..d3d570e70d3b81d602bde803364cf124a6bc5dc3 100644 (file)
@@ -46,6 +46,8 @@ static int nr_recs;
 /* Send virtual interrupt when buffer level reaches this point */
 static int t_buf_highwater;
 
+/* Number of records lost due to per-CPU trace buffer being full. */
+static DEFINE_PER_CPU(unsigned long, lost_records);
 
 /* a flag recording whether initialization has been done */
 /* or more properly, if the tbuf subsystem is enabled right now */
@@ -234,7 +236,7 @@ void trace(u32 event, unsigned long d1, unsigned long d2,
     struct t_buf *buf;
     struct t_rec *rec;
     unsigned long flags;
-
+    
     BUG_ON(!tb_init_done);
 
     if ( (tb_event_mask & event) == 0 )
@@ -259,12 +261,27 @@ void trace(u32 event, unsigned long d1, unsigned long d2,
 
     local_irq_save(flags);
 
-    if ( (buf->prod - buf->cons) >= nr_recs )
+    /* Check if space for two records (we write two if there are lost recs). */
+    if ( (buf->prod - buf->cons) >= (nr_recs - 1) )
     {
+        this_cpu(lost_records)++;
         local_irq_restore(flags);
         return;
     }
 
+    if ( unlikely(this_cpu(lost_records) != 0) )
+    {
+        rec = &t_recs[smp_processor_id()][buf->prod % nr_recs];
+        memset(rec, 0, sizeof(*rec));
+        rec->cycles  = (u64)get_cycles();
+        rec->event   = TRC_LOST_RECORDS;
+        rec->data[0] = this_cpu(lost_records);
+        this_cpu(lost_records) = 0;
+
+        wmb();
+        buf->prod++;
+    }
+
     rec = &t_recs[smp_processor_id()][buf->prod % nr_recs];
     rec->cycles  = (u64)get_cycles();
     rec->event   = event;
index 8fc009dfebe4fd01cc084ffabe3c213e9e7af377..4cb73386c349a21ec5758c837268e43beddca970 100644 (file)
@@ -26,6 +26,7 @@
 #define TRC_VMXIO    0x00088000   /* VMX io emulation trace  */
 
 /* Trace events per class */
+#define TRC_LOST_RECORDS        (TRC_GEN + 1)
 
 #define TRC_SCHED_DOM_ADD       (TRC_SCHED +  1)
 #define TRC_SCHED_DOM_REM       (TRC_SCHED +  2)